<template>
    <div>
        <el-steps :active="active" finish-status="success">
            <el-step title="基本信息"></el-step>
            <el-step title="商信信息"></el-step>
            <el-step title="完成"></el-step>
        </el-steps>
        <div v-if="showPrise">
            <div class="container">
                <div class="crumbs">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item>
                            <i class="el-icon-lx-calendar"></i> 企业基本信息
                        </el-breadcrumb-item>
                    </el-breadcrumb>
                </div>
                <div class="form-box">
                    <el-form  :model="form" :ref="formRules" ref="form" label-width="150px">
                        <el-form-item label="企业名称" required prop="companyName">
                            <el-input v-model="form.companyName" ></el-input>
                        </el-form-item>
                        <el-form-item label="地址" required  prop="options">
                           <!-- <area-select prop="options"  v-model="form.options" :data="$pcaa" type="text" :level="3"></area-select>-->
                            <area-cascader  v-model="form.options" :data="$pcaa" type="text" :level="2"></area-cascader>
                            <el-input type="textarea" placeholder="请输入详细地址" prop="address" v-model="form.address" ></el-input>
                        </el-form-item>

                        <el-form-item label="Email" prop="mailbox" required>
                            <el-input v-model="form.mailbox" prop="mailbox"></el-input>
                        </el-form-item>
                        <el-form-item label="电话号码" required prop="phone">
                            <el-input v-model="form.phone" ></el-input>
                        </el-form-item>
                        <el-form-item label="官网" prop="officialWebsite">
                            <el-input v-model="form.officialWebsite" ></el-input>
                        </el-form-item>
                        <el-form-item label="融资" prop="financing">
                            <el-select v-model="form.financing" placeholder="融资" class="handle-select mr10">
                                <el-option key="1" label="请选择" value=""></el-option>
                                <el-option key="2" label="上市" value="上市"></el-option>
                                <el-option key="3" label="A轮" value="A轮"></el-option>
                                <el-option key="4" label="B轮" value="B轮"></el-option>
                                <el-option key="5" label="C轮" value="C轮"></el-option>
                                <el-option key="6" label="天使轮" value="天使轮"></el-option>
                                <el-option key="7" label="被收购" value="被收购"></el-option>
                                <el-option key="8" label="撤销" value="撤销"></el-option>
                                <el-option key="9" label="股权转让" value="股权转让"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="企业简介" prop="briefing" required>
                            <el-input type="textarea" rows="5"   v-model="form.briefing"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button  type="primary" style="margin-top: 12px;" @click="next">下一步</el-button>
                            <el-button @click="resForm('form')">取消</el-button>
                        </el-form-item>
                        </el-form>
                </div>
            </div>
        </div>
        <div v-show="showRentPrise">
            <div class="container">
                <div class="crumbs">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item>
                            <i class="el-icon-lx-calendar"></i> 企业工商信息
                        </el-breadcrumb-item>
                    </el-breadcrumb>
                </div>
                <div class="form-box">
                    <el-form ref="form" :model="form" :rules="formRules" label-width="150px">
                        <el-form-item label="法人" prop="uid" required>
                            <el-select v-model="form.uid" placeholder="法人" class="handle-select mr10" >
                                <el-option key="1" label="请选择法人" value=""></el-option>
                                <el-option
                                        v-for="(item,index) in partnerList"
                                        :key="index+'1'"
                                        :value="item.pid"
                                        :label="item.partnerName"
                                ></el-option>

                            </el-select>
                            <el-button type="text"
                                       icon="el-icon-edit"
                                       @click="handleEdit()" style="margin-left: 20px;">添加法人</el-button>
                        </el-form-item>

                        <el-form-item label="企业类型" prop="typeId" required>
                            <el-select v-model="form.typeId" placeholder="企业类型" class="handle-select mr10"  >
                                <el-option key="1" label="请选择" value=""></el-option>
                                <el-option
                                        v-for="(item,index) in companyTypeList"
                                        :key="index+'1'"
                                        :value="item.tid"
                                        :label="item.typeName"
                                ></el-option>

                            </el-select>
                        </el-form-item>

                        <el-form-item label="组织机构" prop="eid" required>
                            <el-select v-model="form.eid" placeholder="" class="handle-select mr10">
                                <el-option  label="请选择" value=""></el-option>
                                <el-option
                                        v-for="(items,index) in organizationsList"
                                        :key="index+'1'"
                                        :value="items.id"
                                        :label="items.organization"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="注册资本" prop="registerCapital" required>
                            <el-input v-model="form.registerCapital" prop="registerCapital"></el-input>
                        </el-form-item>
                        <el-form-item label="实缴资本" prop="paidCapital" required>
                            <el-input v-model="form.paidCapital" prop="paidCapital"></el-input>
                        </el-form-item>
                        <el-form-item label="登记状态" prop="registerStatus" required>
                            <el-select v-model="form.registerStatus" placeholder="登记状态" class="handle-select mr10">
                                <el-option key="1" label="请选择" value=""></el-option>
                                <el-option key="2" label="在业" value="在业"></el-option>
                                <el-option key="3" label="筹建" value="筹建"></el-option>
                                <el-option key="4" label="清算" value="清算"></el-option>
                                <el-option key="5" label="迁入" value="迁入"></el-option>
                                <el-option key="6" label="迁出" value="迁出"></el-option>
                                <el-option key="7" label="停业" value="停业"></el-option>
                                <el-option key="8" label="撤销" value="撤销"></el-option>
                                <el-option key="9" label="吊销" value="吊销"></el-option>
                                <el-option key="10" label="注销" value="注销"></el-option>
                                <el-option key="11" label="存续" value="存续"></el-option>

                            </el-select>
                        </el-form-item>
                        <el-form-item label="成立日期" prop="createTime" required>
                            <el-date-picker
                                    v-model="form.createTime"
                                    align="right"
                                    type="date"
                                    placeholder="选择日期"
                                    prop="createTime"
                                    :picker-options="startTime">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="核准日期" prop="approvalTime" required>
                            <el-date-picker
                                    v-model="form.approvalTime"
                                    align="right"
                                    type="date"
                                    placeholder="选择日期"
                                    prop="approvalTime"
                                    :picker-options="endTime">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="统一社会信用代码"  required prop="uscc">
                            <el-input v-model="form.uscc"></el-input>
                        </el-form-item>
                        <el-form-item label="组织机构代码" required  prop="ocode">
                            <el-input v-model="form.ocode"></el-input>
                        </el-form-item>
                        <el-form-item label="工商注册号" required prop="bsnumber">
                            <el-input v-model="form.bsnumber" ></el-input>
                        </el-form-item>
                        <el-form-item label="纳税人识别号" required prop="tinumber">
                            <el-input v-model="form.tinumber" ></el-input>
                        </el-form-item>
                        <el-form-item label="进出口企业代码" prop="importNumber">
                            <el-input v-model="form.importNumber"></el-input>
                        </el-form-item>
                        <el-form-item label="行业分类" required prop="industryId">
                            <el-select v-model="form.industryId" placeholder="行业分类" class="handle-select mr10">
                                <el-option  label="请选择" value=""></el-option>
                                <el-option
                                        v-for="(items,index) in industryList"
                                        :key="index+'1'"
                                        :value="items.iuId"
                                        :label="items.industryName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="营业期限" required prop="businessTerm">
                           <!-- <el-input v-model="fromCompanyInfo.businessTerm" prop="businessTerm"></el-input>-->
                            <el-select v-model="form.businessTerm" placeholder="营业期限" class="handle-select mr10">
                                <el-option key="1" label="请选择" value=""></el-option>
                                <el-option key="2" label="5年-10年" value="5年-10年"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="登记机关" required prop="authority">
                            <el-input v-model="form.authority" ></el-input>
                        </el-form-item>
                        <el-form-item label="人员规模" required prop="personnel">
                            <!--<el-input v-model="fromCompanyInfo.personnel" prop="personnel"></el-input>-->
                            <el-select v-model="form.personnel" placeholder="人员规模" class="handle-select mr10">
                                <el-option key="1" label="请选择" value=""></el-option>
                                <el-option key="2" label="20-50人" value="20-50人"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="参保人数" required prop="personsNumber">
                            <!--<el-input v-model="fromCompanyInfo.personsNumber" prop="personsNumber"></el-input>-->
                            <el-select v-model="form.personsNumber" placeholder="参保人数" class="handle-select mr10">
                                <el-option key="1" label="请选择" value="0"></el-option>
                                <el-option key="2" label="10" value="10"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="所属地区" prop="optionsorgin" required>
                       <!-- <el-input v-model="fromCompanyInfo.region" prop="region"></el-input>-->
                            <area-cascader   v-model="form.optionsorgin" :data="$pcaa" type="text" :level="0"></area-cascader>
                    </el-form-item>
                        <el-form-item label="曾用名" prop="oldName">
                            <el-input v-model="form.oldName" ></el-input>
                        </el-form-item>
                        <el-form-item label="英文名" prop="englishName" required>
                            <el-input v-model="form.englishName" ></el-input>
                        </el-form-item>
                        <el-form-item label="经营范围" prop="nature" required>
                            <el-input type="textarea" rows="5" v-model="form.nature" ></el-input>
                        </el-form-item>
                    <el-form-item>
                        <el-button @click="nextOne">上一步</el-button>
                        <el-button  type="primary" style="margin-top: 12px;" @click="onSubmit('form')">提交</el-button>
                        <el-button @click="resForm('form')">取消</el-button>
                    </el-form-item>
                  </el-form >
                </div>

            </div>
        </div>
        <!-- 编辑弹出框 -->
        <el-dialog title="添加法人" :visible.sync="editVisible" width="50%">
            <el-form :model="formPartner" :rules="formPartnerRules" ref="formPartner" label-width="80px" class="demo-ruleForm">
                <el-form-item label="姓名" required prop="partnerName">
                    <el-input v-model="formPartner.partnerName"></el-input>
                </el-form-item>
                <el-form-item label="地址" required prop="opstionAddress">
                    <area-cascader   v-model="formPartner.opstionAddress" :data="$pcaa" type="text" :level="1"></area-cascader>
                </el-form-item>
                <el-form-item label="民族" required prop="nation">
                   <!-- <el-input v-model="formPartner.nation" prop="partnerName"></el-input>-->
                    <el-select v-model="formPartner.nation" placeholder="民族" class="handle-select mr10"  >
                        <el-option  label="请选择民族" value=""></el-option>
                        <el-option
                                v-for="(item,index) in nationList"
                                :key="index+'1'"
                                :value="item.name"
                                :label="item.name"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="性别" required prop="sex">
                    <el-select v-model="formPartner.sex" placeholder="性别" class="handle-select mr10">
                        <el-option key="1" label="请选择性别" value=""></el-option>
                        <el-option key="2" label=" 男" value="0"></el-option>
                        <el-option key="3" label="女" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="学历">
                    <el-select v-model="formPartner.education" placeholder="学历" class="handle-select mr10">
                        <el-option key="1" label="请选择学历" value=""></el-option>
                        <el-option key="2" label=" 学士" value="学士"></el-option>
                        <el-option key="3" label="硕士" value="硕士"></el-option>
                    </el-select>
                </el-form-item>
                <!--<el-form-item label="出生日期" required prop="birthday">
                    <el-date-picker
                            v-model="formPartner.birthday"
                            align="right"
                            type="date"
                            placeholder="选择日期"
                            prop="birthday"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>-->
                <el-form-item label="身份证号" required prop="identification">
                    <el-input v-model="formPartner.identification"  prop="identification"></el-input>
                </el-form-item>
                <el-form-item label="党派">
                    <el-select v-model="formPartner.organization" placeholder="党派" class="handle-select mr10">
                        <el-option key="1" label="请选择" value=""></el-option>
                        <el-option key="2" label="共产党" value="共产党"></el-option>
                        <el-option key="3" label="民建" value="民建"></el-option>
                        <el-option key="4" label="民盟" value="民盟"></el-option>
                        <el-option key="5" label="九三学社" value="九三学社"></el-option>
                        <el-option key="6" label="台盟" value="台盟"></el-option>
                        <el-option key="7" label="农工党" value="农工党"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item  label="曾用名">
                    <el-input v-model="formPartner.oldName"></el-input>
                </el-form-item>
                <el-form-item  label="英文名">
                    <el-input v-model="formPartner.englishName"></el-input>
                </el-form-item>
                <el-form-item label="简介" required prop="briefIntroduction">
                    <el-input type="textarea" rows="5" v-model="formPartner.briefIntroduction"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="resetForm('formPartner')">取 消</el-button>
                <el-button type="primary" @click="saveEdit('formPartner')">确定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import Vue from 'vue';
    import { pcaa } from 'area-data-vue';
    import 'area-linkage-vue/dist/index.css';
    import AreaLinkageVue from 'area-linkage-vue';
    Vue.prototype.$pcaa = pcaa;
    Vue.use(AreaLinkageVue)
    export default {
        name: 'CompanyEditor',
        data() {
            /**
             * 电话号码校验
             * */
            var checkPhone = (rule, value, callback) => {
                const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/
                if (!value) {
                    return callback(new Error('电话号码不能为空'))
                }
                setTimeout(() => {
                    // Number.isInteger是es6验证数字是否为整数的方法,但是我实际用的时候输入的数字总是识别成字符串
                    // 所以我就在前面加了一个+实现隐式转换

                    if (!Number.isInteger(+value.trim())) {
                    callback(new Error('请输入数字值'))
                } else {
                    if (phoneReg.test(value)) {
                        callback()
                    } else {
                        callback(new Error('电话号码格式不正确'))
                    }
                }
            }, 100)
            }
            /**
             * 邮箱校验
             * */
            var checkEmail = (rule, value, callback) => {
                const mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/
                if (!value) {
                    return callback(new Error('邮箱不能为空'))
                }
                setTimeout(() => {
                    if (mailReg.test(value.trim())) {
                    callback()
                } else {
                    callback(new Error('请输入正确的邮箱格式'))
                }
            }, 100)
            }
            /**
             * 公司名称校验
             * */
            var companyNameC =(rule, value, callback) => {
                //校验中文的正则：/^[\u4e00-\u9fa5]{0,}$/
                const re= /^[\u4e00-\u9fa5]+$/
                if (!value) {
                    return callback(new Error('公司名称不能为空'))
                }
                setTimeout(() => {
                    if (re.test(value.trim())) {
                        console.log(this.companyList.length)
                        var length=this.companyList.length;
                        for (var i =0;i<length;i++) {
                            if (this.companyList[i].companyName == value){
                                callback(new Error('公司名称已存在'))
                                return
                            }else {
                                callback()
                            }
                        }
                } else {
                    callback(new Error('请输入正确的公司名称'))
                }
            }, 100)
            }
            /**
             * 统一社会信用代码校验
             * */
            var cheackCreditCode =(rule, value, callback) => {
                if (!value) {
                    return callback(new Error('统一社会信用代码不能为空'))
                }
                setTimeout(() => {
                    if (this.CheckSocialCreditCode(value.trim()) == true) {
                    for (var i =0;i<this.companyList.length;i++) {
                        if (this.companyList[i].USCC == value){
                            callback(new Error('请输入正确的统一社会信用代码'))
                            return
                        }else {
                            callback()
                        }
                    }
                }else {
                    callback(new Error('请输入正确的统一社会信用代码'))
                }
            }, 100)
           }
            /**
             * 纳税人识别号校验
             */
            var tINumber=(rule, value, callback) => {
                if (!value) {
                    return callback(new Error('纳税人识别号不能为空'))
                }
                setTimeout(() => {
                    if (this.CheckSocialCreditCode(value.trim()) == true) {
                    for (var i =0;i<this.companyList.length;i++) {
                        if (this.companyList[i].tINumber == value){
                            callback(new Error('请输入正确的纳税人识别号'))
                            return
                        }else {
                            callback()
                        }
                    }
                }else {
                    callback(new Error('请输入正确的纳税人识别号'))
                }
            }, 100)
            }
            /**
             * 工商注册号校验
             * */
            var bSNumber =(rule, value, callback) => {
                //工商注册号的正则：/^[1-7]\d{14}$/
                const re= /^[1-7]\d{14}$/
                if (!value) {
                    return callback(new Error('工商注册号不能为空'))
                }
                setTimeout(() => {
                    if (re.test(value.trim())) {
                    for (var i =0;i<this.companyList.length;i++) {
                        if (this.companyList[i].bSNumber == value){
                            callback(new Error('工商注册号已存在'))
                            return
                        }else {
                            callback()
                        }
                    }
                } else {
                    callback(new Error('请输入正确的工商注册号'))
                }
            }, 100)
            }
            /***
             * 组织机构代码校验
             */
            var oCode =(rule, value, callback) => {
                //组织机构代码的正则：/^\d{8}-?\d{1}$/
                const reg = /^\d{8}-?\d{1}$/;
                if (!value) {
                    return callback(new Error('组织机构代码不能为空'))
                }
                setTimeout(() => {
                    if (reg.test(value.trim())) {
                    for (var i =0;i<this.companyList.length;i++) {
                        if (this.companyList[i].oCode == value){
                            callback(new Error('组织机构代码已存在'))
                            return
                        }else {
                            callback()
                        }
                    }
                } else {
                    callback(new Error('请输入正确的组织机构代码'))
                }
            }, 100)
            }
            /**
             * 英文名字校验
             */
            var englishName =(rule, value, callback) => {
                const reg =/^[a-zA-Z&.,\'\/\-\s]+$/g;
                if (!value) {
                    return callback(new Error('英文名称不能为空'))
                }
                setTimeout(() => {
                    if (reg.test(value.trim())) {
                            callback()
                } else {
                    callback(new Error('请输入正确的英文名称'))
                }
            }, 100)
            }
            /**
             * 身份证号校验
             */
            var identi =(rule, value, callback) => {
                //身份证号的正则：/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i
                const reg =/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
                if (!value) {
                    return callback(new Error('身份证号不能为空'))
                }
                setTimeout(() => {
                    if (reg.test(value.trim())) {
                    //获取计算后出生日期
                    var birthDateStr = this.getBirthdayFromIdCard(value);
                    //获取当前的日期
                    var nowDateStr = this.getNowDate();
                    //获取计算后年龄(两个日期之间)
                    var age = this.getAge(birthDateStr, nowDateStr);
                    if(age >= 18){
                        callback()
                    }else {
                        callback(new Error('您为抵达合法年龄'))
                    }

                } else {
                    callback(new Error('请输入正确的身份证号'))
                }
            }, 100)
            }
            /**
             * 数字校验
             */
            var isNum = (rule, value, callback) => {
                var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
                if (reg.test(value)) {
                    callback()
                }else{

                    callback(new Error('请输入有效字符'))
                }
            }
            return {
                form: {
                    cid:'',
                    companyName: '',
                    phone: '',
                    mailbox: '',
                    officialWebsite: '',
                    briefing:'',
                    options: [],
                    optionsorgin: [],
                    address:'',
                    uid: '',
                    typeId: '',
                    eid: '',
                    registerCapital: '',
                    paidCapital: '',
                    registerStatus: '',
                    createTime:'' ,
                    approvalTime: '',
                    uscc: '',
                    ocode: '',
                    bsnumber: '',
                    tinumber: '',
                    importNumber:'',
                    industryId: '',
                    businessTerm: '',
                    authority: '',
                    personnel: '',
                    personsNumber: '',
                    region: '',
                    oldName: '',
                    englishName: '',
                    financing:'',
                    nature: '',
                    a:[],
                    b:[],
                    c:''
                },
                formRules:{
                    companyName: [
                        { required: true,validator: companyNameC, trigger: 'blur' }
                    ],
                    phone: [
                        { required: true,type: 'number',validator: checkPhone, message: '请填写正确的手机号', trigger: 'blur' },
                    ],
                    mailbox: [
                        { required: true,validator: checkEmail, message: '请填写正确的邮箱', trigger: 'blur' }
                    ],
                    officialWebsite:[
                        { type:'url', message: '请填写正确的网址', trigger: 'blur' }
                    ],
                    options: [
                        { required: true, message: '请选择地址', trigger: 'change' }
                    ],
                    uid: [
                        { required: true, message: '请选择法人', trigger: 'change' }
                    ],
                    typeId: [
                        { required: true, message: '请选择企业类型', trigger: 'change' }
                    ],
                    eid: [
                        { required: true, message: '请选择经济性质', trigger: 'change' }
                    ],
                    industryId: [
                        { required: true, message: '请选择所属行业', trigger: 'change' }
                    ],
                    businessTerm:[
                        { required: true, message: '请选择', trigger: 'change' }
                    ],
                    personnel:[
                        { required: true, message: '请选择', trigger: 'change' }
                    ],
                    personsNumber:[
                        { required: true, message: '请选择', trigger: 'change' }
                    ],
                    optionsorgin:[
                        {  required: true, message: '请选择区域', trigger: 'change' }
                    ],
                    registerStatus: [
                        { required: true, message: '请选择登记状态', trigger: 'change' }
                    ],
                    registerCapital: [
                        { required: true, validator:isNum, message: '请填写注册资本', trigger: 'blur' }
                    ],
                    paidCapital: [
                        { required: true,validator:isNum, message: '请填写实缴资本', trigger: 'blur' }
                    ],
                    createTime: [
                        { required: true, message: '请选择日期', trigger: 'change' }
                    ],
                    approvalTime: [
                        {  required: true, message: '请选择日期', trigger: 'change' }
                    ],

                    uscc: [
                        {  required: true,validator:cheackCreditCode, message: '请输入统一社会信用代码', trigger: 'blur' }
                    ],
                    ocode: [
                        { required: true,validator:oCode, message: '请输入组织机构代码', trigger: 'blur' }
                    ],
                    bsnumber: [
                        {  required: true, validator:bSNumber,message: '请输入工商注册号', trigger: 'blur' }
                    ],
                    tinumber: [
                        {  required: true,validator:tINumber, message: '请输入纳税人识别号', trigger: 'blur' }
                    ],
                    authority: [
                        {  required: true, message: '请输入登记机关', trigger: 'blur' }
                    ],
                    englishName: [
                        {  required: true,validator:englishName, message: '请输入英文名', trigger: 'blur' }
                    ],
                    nature: [
                        { required: true, message: '请输入经营范围', trigger: 'blur' }
                    ],
                    briefing:[
                        { required: true, message: '请输入公司简介', trigger: 'blur' }
                    ]},
                formPartner:{
                    partnerName: "",
                    opstionAddress: [],
                    nation: "",
                    sex: "",
                    education: "",
                    birthday: "",
                    organization: "",
                    englishName: "",
                    oldName: "",
                    briefIntroduction:"",
                    address:"",
                    identification:"",
                    b:""
                },
                formPartnerRules: {
                    partnerName: [
                        { required: true, message: '请输入法人名称', trigger: 'blur' },
                        { min: 2, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ],
                    sex: [
                        { required: true, message: '请选择性别', trigger: 'change' }
                    ],
                    nation: [
                        { required: true, message: '请选择民族', trigger: 'change' }
                    ],
                    opstionAddress: [
                        { required: true, message: '请选择地址', trigger: 'change' }
                    ],
                    identification: [
                        {  required: true,validator:identi, message: '填写正确的身份证号', trigger: 'blur' }
                    ],

                    briefIntroduction:[
                        { required: true, message: '请输入个人简介', trigger: 'blur' }
                    ]
                },
                // 开始时间小于结束时间，且开始时间小于此刻
                startTime: {
                    disabledDate: time => {
                    if (this.form.approvalTime) {
                        return time.getTime() > new Date(this.form.approvalTime).getTime()
                    } else {
                        return time.getTime() > Date.now()
                    }
                }
            },
            // 结束时间大于开始时间，且小于此刻
            endTime:{
                disabledDate:time => {
                    if (this.form.createTime) {
                        return time.getTime() > Date.now() || time.getTime() < new Date(this.form.createTime).getTime()
                    } else {
                        return time.getTime() > Date.now()
                    }
                }
            },
            active: 0,
            showPrise:true,
            showRentPrise:false,
            editVisible: false,
            partnerList:{},
            companyTypeList:{},
            organizationsList:{},
            industryList:{},
            nationList:{},
            companyList:{}

            };
        },
        created() {
            this.getPartner();
            this.typeList();
            this.organizationsGetData();
            this.getIndustry();
            this.getNationList();
            this. editor();
            this.getCompany();

        },
        methods: {
            onSubmit(formName) {
                const _this = this;
                _this.$refs[formName].validate((valid) => {
                    if(valid) {
                        _this.form.a = _this.form.options.toString();
                        _this.form.b = _this.form.optionsorgin.toString();
                        _this.form.c = _this.form.address
                        _this.form.region = _this.form.optionsorgin[0] + _this.form.optionsorgin[1];
                        _this.form.address = _this.form.options[1] + _this.form.options[2] + _this.form.options[3] + _this.form.address;
                        _this.$axios.post("/companydata/saveEdit", _this.form).then(res => {
                            if(res.status = 200)
                        {
                            this.$message.success(res.data.msg);
                            this.$router.push('/table');
                        }
                    else
                        {
                            this.$message.error(res.data.msg);
                        }
                    });
                    } else {
                        console.log('error submit!!');
                return false;
            }
            });

            },
            next() {
                const _this = this;
                if (_this.active++ > 2) _this.active = 0;
                if (_this.active == 0) {
                    _this.showPrise = true;
                } else if (_this.active == 1) {
                    _this.showPrise = false;
                    _this.showRentPrise = true
                }

            },
            nextOne() {
                const _this = this;
                if (_this.active-- < 0) _this.active = 0;
                if (_this.active == 0) {
                    _this.showPrise = true;
                    _this.showRentPrise = false;
                } else if (_this.active == 1) {
                    _this.showRentPrise = true
                }

            },
            getPartner() {
                const _this = this
                _this.$axios.get("/partner/finaAll").then(res => {
                    _this.partnerList = res.data.data
            })
            },
            typeList() {
                const _this = this
                _this.$axios.get("/companytype/finaAll").then(res => {
                    _this.companyTypeList = res.data.data
            })
            },
            organizationsGetData() {
                const _this = this
                _this.$axios.get("/organizations/finaAll").then(res => {
                    _this.organizationsList = res.data.data
            })
            },
            getIndustry() {
                const _this = this
                _this.$axios.get("/industry/finaAll").then(res => {
                    _this.industryList = res.data.data
            })
            },
            getNationList() {
                const _this = this;
                _this.$axios.get("/utils/nationList").then(res => {
                    _this.nationList = res.data.data.data;


            })
                ;
            },
            getCompany() {
                const _this = this
                _this.$axios.get("/companydata/finaAll").then(res =>  {
                    _this.companyList = res.data.data
            })

            },
            // 编辑操作
            handleEdit() {
                this.editVisible = true;
            },
            saveEdit(formName) {
                const _this = this;
                _this.$refs[formName].validate((valid) => {
                    if(valid) {
                        _this.formPartner.birthday=_this.getBirthdayFromIdCard( _this.formPartner.identification);
                        _this.formPartner.address = _this.formPartner.opstionAddress[1] + _this.formPartner.opstionAddress[2];
                        _this.formPartner.b= _this.formPartner.opstionAddress.toString();
                        _this.$axios.post("/partner/saveEdit", _this.formPartner).then(res => {
                        _this.from.uid = res.data.data[res.data.data.length - 1].pid


                    })
                        ;
                        this.editVisible = false;
                    } else {
                        console.log('error submit!!');
                return false;
            }
            });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.editVisible = false;
            },
            resForm(formName) {
                this.$refs[formName].resetFields();
                this.$router.go(-1);
            },
            editor() {
                if (this.$route.query.cid != undefined) {
                    this.form.address = '';
                    this.$axios.get('/companydata/editor/' + this.$route.query.cid).then(res => {
                    this.form.cid = res.data.data.cid;
                    this.form.companyName = res.data.data.companyName;
                    this.form.phone = res.data.data.phone;
                    this.form.mailbox = res.data.data.mailbox;
                    this.form.officialWebsite = res.data.data.officialWebsite;
                    this.form.briefing = res.data.data.briefing;
                    this.form.typeId = res.data.data.typeId;
                    this.form.eid = res.data.data.eid;
                    this.form.registerCapital = res.data.data.registerCapital;
                    this.form.paidCapital = res.data.data.paidCapital;
                    this.form.uid = res.data.data.uid;
                    this.form.registerStatus = res.data.data.registerStatus;
                    this.form.ocode = res.data.data.ocode;
                    this.form.bsnumber = res.data.data.bsnumber;
                    this.form.tinumber = res.data.data.tinumber;
                    this.form.importNumber = res.data.data.importNumber;
                    this.form.businessTerm = res.data.data.businessTerm;
                    this.form.authority = res.data.data.authority;
                    this.form.personnel = res.data.data.personnel;
                    this.form.personsNumber = res.data.data.personsNumber;
                    this.form.oldName = res.data.data.oldName;
                    this.form.englishName = res.data.data.englishName;
                    this.form.nature = res.data.data.nature;
                    this.form.industryId = res.data.data.industryId;
                    this.form.uscc = res.data.data.uscc;
                    this.form.address = res.data.data.c;
                    this.form.approvalTime = res.data.data.approvalTime[0];
                    this.form.createTime = res.data.data.createTime[0];
                    if(res.data.data.a !=undefined){
                        this.form.options = res.data.data.a.split(","); // 用,分割
                    }

                    this.form.optionsorgin = res.data.data.b.split(","); // 用,分割
                });
                } else {
                    this.from = {};
                }
            },
            CheckSocialCreditCode(Code) {
                var patrn = /^[0-9A-Z]+$/; //18位校验及大写校验
                if (Code.length != 18 || patrn.test(Code) == false) {
                    return false;
                } else {
                    var Ancode; //统一社会信用代码的每一个值
                    var Ancodevalue; //统一社会信用代码每一个值的权重
                    var total = 0;
                    var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28]; //加权因子
                    var str = "0123456789ABCDEFGHJKLMNPQRTUWXY"; //不用I、O、S、V、Z
                    for (var i = 0; i < Code.length - 1; i++) {
                        Ancode = Code.substring(i, i + 1);
                        Ancodevalue = str.indexOf(Ancode);
                        total = total + Ancodevalue * weightedfactors[i]; //权重与加权因子相乘之和
                    }
                    var logiccheckcode = 31 - (total % 31);
                    if (logiccheckcode == 31) {
                        logiccheckcode = 0;
                    }
                    var Str =
                        "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";
                    var Array_Str = Str.split(",");
                    logiccheckcode = Array_Str[logiccheckcode];
                    var checkcode = Code.substring(17, 18);
                    if (logiccheckcode != checkcode) {
                        return false;
                    }
                    return true;
                }
            },
            getBirthdayFromIdCard(idCard) {
                var birthday = "";
                if(idCard != null && idCard != ""){
                    if(idCard.length == 15){
                        birthday = "19"+idCard.substr(6,6);
                    } else if(idCard.length == 18){
                        birthday = idCard.substr(6,8);
                    }
                    birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
                }
                return birthday;
            },
            //获取当前日期
            getNowDate() {
                var d = new Date();
                var year = d.getFullYear();
                var month = d.getMonth() + 1;
                var day = d.getDate();
                var dateStr = year + '-' + this.getFormatDate(month) + '-' + this.getFormatDate(day);
                return dateStr;
            },
            //格式化日期的月份或天数的显示（小于10，在前面增加0）
            getFormatDate(value) {
                if (value == undefined || value == "") {
                    return '';
                }
                var str = value;
                if (parseInt(value) < 10) {
                    str = '0' + value;
                }
                return str;
            },
            //根据两个日期计算年龄（是否过生日）
            getAge(startDateStr, endDateStr)
            {
                //计算两个日期相差多少年
                var startDate = new Date(startDateStr);
                var endDate = new Date(endDateStr);
                var yearNum = endDate.getFullYear() - startDate.getFullYear();
                //获取两个日期（月+日）部分
                var sStr = startDateStr.substring(5, 10);
                var eStr = endDateStr.substring(5, 10);
                //判断两个日期大小
                //判断是否过生日
                if (new Date(sStr) <= new Date(eStr)) {
                    return yearNum + 1;
                }
                else {
                    return yearNum;
                }
            }

    },

    };
</script>


<style scoped>
    .form-box {
        width: 800px;

    }
    .area-select span{
        padding:-8px -20px -10px -20px;
        text-align: center;
    }
    .tags-text{
        margin-top:10px ;
        margin-left:10px ;
        width: 600px;
    }
    .crumbs {
         margin: -10px 0;
         padding-bottom: 25px;
    }
</style>